package com.telecomyt.jwportal.activity.person;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chaychan.library.BottomBarItem;
import com.chaychan.library.BottomBarLayout;
import com.telecomyt.jwportal.R;
import com.telecomyt.jwportal.activity.person.bean.PersonInfoBean;
import com.telecomyt.jwportal.base.BaseActivity;
import com.telecomyt.jwportal.net.network.NetType;
import com.telecomyt.jwportal.net.network.Network;
import com.telecomyt.jwportal.net.network.NetworkManager;
import com.telecomyt.jwportal.utils.ToastUtils;
import com.telecomyt.jwportal.widget.FraToolBar;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @date: 2020/8/31
 * @author: chengDa
 * @description: 个人信息
 */
public class PersonalDetailsActivity extends BaseActivity<PersonPresenter> implements PersonContract.View {
    private static final String TAG = "PersonalDetailsActivity";
    @BindView(R.id.mFraToolBar)
    FraToolBar mFraToolBar;
    @BindView(R.id.mTvName)
    TextView mTvName;
    @BindView(R.id.mTvAddress)
    TextView mTvAddress;
    @BindView(R.id.mTvPersonName)
    TextView mTvPersonName;
    @BindView(R.id.mTvPersonSection)
    TextView mTvPersonSection;
    @BindView(R.id.mTvPersonDesignation)
    TextView mTvPersonDesignation;
    @BindView(R.id.mTvTitle)
    TextView mTvTitle;
    @BindView(R.id.mTvPersonMobile)
    TextView mTvPersonMobile;
    @BindView(R.id.mRlPhone)
    RelativeLayout mRlPhone;
    @BindView(R.id.mBottomBarLayout)
    BottomBarLayout mBottomBarLayout;
    private String telephone;
    private int userId;
    private int tenantId;

    public static void start(Context context, int userId, int tenantId) {
        Intent starter = new Intent(context, PersonalDetailsActivity.class);
        starter.putExtra("userId", userId);
        starter.putExtra("tenantId", tenantId);
        context.startActivity(starter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_personal_details;
    }

    @Override
    protected void initView() {
        NetworkManager.getInstance().registerObserver(this);
        userId = getIntent().getIntExtra("userId", -1);
        tenantId = getIntent().getIntExtra("tenantId", -1);
        mFraToolBar.setLeftFinish(this);
        mFraToolBar.setRightIconOnCLickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("点击了X");
            }
        });
        mBottomBarLayout.setOnItemSelectedListener(new BottomBarLayout.OnItemSelectedListener() {
            @Override
            public void onItemSelected(BottomBarItem bottomBarItem, int i, int position) {
                switch (position) {
                    case 0:
                        ToastUtils.showShort("视频");
                        break;
                    case 1:
                        ToastUtils.showShort("语音");
                        break;
                    case 2:
                        ToastUtils.showShort("对讲");
                        break;
                    case 3:
                        ToastUtils.showShort("消息");
                        break;
                }
            }
        });


//        mBottomBarLayout.setUnread(0, 20);//设置第一个页签的未读数为20
//        mBottomBarLayout.setUnread(1, 101);//设置第二个页签的未读数
//        mBottomBarLayout.showNotify(2);//设置第三个页签显示提示的小红点
//        mBottomBarLayout.setMsg(3, "NEW");//设置第四个页签显示NEW提示文字
    }


    @Network(netType = NetType.AUTO)
    public void onNetChanged(NetType netType) {
        switch (netType) {
            case WIFI:
            case MOBILE:
            case AUTO:
                Log.e(TAG, "AUTO监控：CONNECT");
                showNetWork(false);
                break;
            case NONE:
                showNetWork(true);
                ToastUtils.showShort("网络连接失败,请检查网络");
                Log.e(TAG, "AUTO监控：NONE CONNECT");
                break;
            default:
                break;
        }
    }

    @Override
    protected void initData() {
        persenter.getPersonData(userId, tenantId);

    }

    @Override
    protected PersonPresenter creatPresenter() {
        return new PersonPresenter(this);
    }

    @Override
    public void setPersonInfo(PersonInfoBean bean) {
        telephone = bean.getTelephone();
        mTvName.setText(bean.getName());
        mTvPersonName.setText(bean.getName());
        mTvPersonMobile.setText(telephone);
        List<PersonInfoBean.DeptsBean> depts = bean.getDepts();
        if (depts != null && depts.size() > 0) {
            mTvPersonSection.setText(depts.get(0).getDeptName());
        }
    }

    @OnClick(R.id.mRlPhone)
    public void onViewClicked() {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        NetworkManager.getInstance().unRegisterObserver(this);
    }


}